package cate.game.pvp.championrace;

import cate.common.util.GameResult;
import cate.game.framework.ModuleMan;
import cate.game.pvp.championrace.data.*;
import cate.game.pvp.championrace.dto.*;
import cate.game.role.RoleSnapshot;
import cate.game.role.pvp.championrace.msg.*;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class GameChampionRaceMsgManager extends ModuleMan {
    @Override
    public void initDependent() throws Exception {

    }

    public ChampionRaceRedPacketRecordData getRedPacket(RoleSnapshot snapshot, ChampionRaceSpec spec) {
        try {
            return game.rpcSend().requestResponseCross(ChampionRaceMsg.GET_RED_PACKET, GetRedPacketParam.of(snapshot, spec), ChampionRaceRedPacketRecordData.class);
        } catch (Exception e) {
            log.error("跨服冠军赛 GET_RED_PACKET 失败 ", e);
        }
        return null;
    }

    public ChampionRaceRedPacketRecordData getRoleRedPacket(ChampionRaceSpec spec, String roleUid) {
        try {
            return game.rpcSend().requestResponseCross(ChampionRaceMsg.GET_ROLE_RED_PACKET, GetRoleRedPacketParam.of(spec, roleUid), ChampionRaceRedPacketRecordData.class);
        } catch (Exception e) {
            log.error("跨服冠军赛 GET_ROLE_RED_PACKET 失败 ", e);
        }
        return null;
    }

    public boolean hasRecvdRedPacket(ChampionRaceSpec spec, String roleUid) {
        try {
            return game.rpcSend().requestResponseCross(ChampionRaceMsg.HAS_RECVD_RED_PACKET, QueryRedPacketParam.of(spec, roleUid), Boolean.class);
        } catch (Exception e) {
            log.error("跨服冠军赛 HAS_RECVD_RED_PACKET 失败 ", e);
        }
        return false;
    }

    public ChampionRaceBetRecord getBetRecord(ChampionRaceSpec spec) {
        try {
            return game.rpcSend().requestResponseCross(ChampionRaceMsg.GET_BET_RECORD, spec, ChampionRaceBetRecord.class);
        } catch (Exception e) {
            log.error("跨服冠军赛 GET_BET_RECORD 失败", e);
        }
        return null;
    }

    public ChampionRaceAllBetRecordsData getAllBets() {
        try {
            return game.rpcSend().requestResponseCross(ChampionRaceMsg.GET_BET_RECORD_ALL, null, ChampionRaceAllBetRecordsData.class);
        } catch (Exception e) {
            log.error("跨服冠军赛 GET_BET_RECORD_ALL 失败", e);
        }
        return null;
    }

    public ChampionRaceRank getRankData(String roleUid) {
        try {
            return game.rpcSend().requestResponseCross(ChampionRaceMsg.GET_RANK_DATA, roleUid, ChampionRaceRank.class);
        } catch (Exception e) {
            log.error("跨服冠军赛 GET_RANK_DATA 失败", e);
        }
        return null;
    }

    public ChampionRaceRankListData getRankList() {
        try {
            return game.rpcSend().requestResponseCross(ChampionRaceMsg.GET_RANK_LIST, null, ChampionRaceRankListData.class);
        } catch (Exception e) {
            log.error("跨服冠军赛 GET_RANK_LIST 失败", e);
        }
        return null;
    }

    public ChampionRaceBetRoundResp getBetRounds(ChampionRaceBetRoundReq req) {
        try {
            return game.rpcSend().requestResponseCross(ChampionRaceMsg.GET_BET_ROUND_REQ, req, ChampionRaceBetRoundResp.class);
        } catch (Exception e) {
            log.error("跨服冠军赛 GET_BET_ROUND_REQ 失败", e);
        }
        return null;
    }

    public ChampionRaceBetRoundReportResp getBetRoundReports(ChampionRaceBetRoundReportReq req) {
        try {
            return game.rpcSend().requestResponseCross(ChampionRaceMsg.GET_BET_ROUND_REPORT_REQ, req, ChampionRaceBetRoundReportResp.class);
        } catch (Exception e) {
            log.error("跨服冠军赛 GET_BET_ROUND_REPORT_REQ 失败", e);
        }
        return null;
    }

    public ChampionRaceRoundResp getRounds(String roleUid, ChampionRaceRoundReq req) {
        try {
            return game.rpcSend().requestResponseCross(ChampionRaceMsg.GET_ROUND_REQ, RoundReqParam.of(roleUid, req), ChampionRaceRoundResp.class);
        } catch (Exception e) {
            log.error("跨服冠军赛 GET_ROUND_REQ 失败", e);
        }
        return null;
    }

    public ChampionRaceRoundReportResp getRoundReports(String roleUid, ChampionRaceRoundReportReq req) {
        try {
            return game.rpcSend().requestResponseCross(ChampionRaceMsg.GET_ROUND_REPORT_REQ, RoundReportReqParam.of(roleUid, req), ChampionRaceRoundReportResp.class);
        } catch (Exception e) {
            log.error("跨服冠军赛 GET_ROUND_REPORT_REQ 失败", e);
        }
        return null;
    }

    public ChampionRaceGroupRoundResp getGroupRound(ChampionRaceGroupRoundReq req) {
        try {
            return game.rpcSend().requestResponseCross(ChampionRaceMsg.GET_GROUP_ROUND_REQ, req, ChampionRaceGroupRoundResp.class);
        } catch (Exception e) {
            log.error("跨服冠军赛 GET_GROUP_ROUND_REQ 失败", e);
        }
        return null;
    }

    public ChampionRaceGroupRoundReportResp getGroupRoundReports(ChampionRaceGroupRoundReportReq req) {
        try {
            return game.rpcSend().requestResponseCross(ChampionRaceMsg.GET_GROUP_ROUND_REPORT_REQ, req, ChampionRaceGroupRoundReportResp.class);
        } catch (Exception e) {
            log.error("跨服冠军赛 GET_GROUP_ROUND_REPORT_REQ 失败", e);
        }
        return null;
    }

    public ChampionRaceGetPsResp getPs(ChampionRaceGetPsReq req) {
        try {
            return game.rpcSend().requestResponseCross(ChampionRaceMsg.GET_PS_REQ, req, ChampionRaceGetPsResp.class);
        } catch (Exception e) {
            log.error("跨服冠军赛 GET_PS_REQ 失败", e);
        }
        return null;
    }

    public ChampionRaceManyPsData getManyPs(int srvId) {
        try {
            return game.rpcSend().requestResponseCross(ChampionRaceMsg.GET_PS_MANY, srvId, ChampionRaceManyPsData.class);
        } catch (Exception e) {
            log.error("跨服冠军赛 GET_PS_MANY 失败", e);
        }
        return null;
    }

    public ChampionRaceSpecPlayersData getSpecPlayer(int srvId, ChampionRaceSpec spec) {
        try {
            return game.rpcSend().requestResponseCross(ChampionRaceMsg.GET_SPEC_PLAYERS, QuerySpecPlaysParam.of(spec, srvId), ChampionRaceSpecPlayersData.class);
        } catch (Exception e) {
            log.error("跨服冠军赛 GET_SPEC_PLAYERS 失败", e);
        }
        return null;
    }

    public void updatePs(ChampionRaceSpec spec, ChampionRacePs ps) {
        try {
            game.rpcSend().fireAndForgetCross(ChampionRaceMsg.UPDATE_PS, UpdatePsParam.of(spec, ps));
        } catch (Exception e) {
            log.error("跨服冠军赛 UPDATE_PS 失败", e);
        }
    }

    public ChampionRaceRankRewardData getRankReward(int season, int srvId) {
        try {
            return game.rpcSend().requestResponseCross(ChampionRaceMsg.GET_RANK_REWARD, QueryParam.of(season, srvId), ChampionRaceRankRewardData.class);
        } catch (Exception e) {
            log.error("跨服冠军赛 GET_RANK_REWARD 失败", e);
        }
        return null;
    }

    public ChampionRaceBetRecord handleBetReq(ChampionRaceSpec spec, ChampionRaceBetReq req) {
        try {
            return game.rpcSend().requestResponseCross(ChampionRaceMsg.BET_REQ, BetParam.of(spec, req), ChampionRaceBetRecord.class);
        } catch (Exception e) {
            log.error("跨服冠军赛 BET_REQ 失败", e);
        }
        return null;
    }

    public GameResult admire(String roleUid, int index) {
        try {
            return game.rpcSend().requestResponseCross(ChampionRaceMsg.ADMIRE_REQ, AdmireParam.of(roleUid, index), GameResult.class);
        } catch (Exception e) {
            log.error("跨服冠军赛 ADMIRE_REQ 失败", e);
        }
        return new GameResult().fail("失败拉");
    }

    @Data
    public static class BetParam {
        private ChampionRaceSpec spec;
        private ChampionRaceBetReq req;

        public static BetParam of(ChampionRaceSpec spec, ChampionRaceBetReq req) {
            BetParam param = new BetParam();
            param.setSpec(spec);
            param.setReq(req);
            return param;
        }
    }

    @Data
    public static class GetRoleRedPacketParam {
        private ChampionRaceSpec spec;
        private String uid;

        public static GetRoleRedPacketParam of(ChampionRaceSpec spec, String uid) {
            GetRoleRedPacketParam param = new GetRoleRedPacketParam();
            param.setSpec(spec);
            param.setUid(uid);
            return param;
        }
    }

    @Data
    public static class GetRedPacketParam {
        private RoleSnapshot snapshot;
        private ChampionRaceSpec spec;

        public static GetRedPacketParam of(RoleSnapshot snapshot, ChampionRaceSpec spec) {
            GetRedPacketParam param = new GetRedPacketParam();
            param.setSnapshot(snapshot);
            param.setSpec(spec);
            return param;
        }
    }

    @Data
    public static class QueryParam {
        private int season;
        private int srvId;

        public static QueryParam of(int season, int srvId) {
            QueryParam param = new QueryParam();
            param.setSeason(season);
            param.setSrvId(srvId);
            return param;
        }
    }

    @Data
    public static class RoundReqParam {
        private String uid;
        private ChampionRaceRoundReq req;

        public static RoundReqParam of(String uid, ChampionRaceRoundReq req) {
            RoundReqParam param = new RoundReqParam();
            param.setUid(uid);
            param.setReq(req);
            return param;
        }
    }

    @Data
    public static class RoundReportReqParam {
        private String uid;
        private ChampionRaceRoundReportReq req;

        public static RoundReportReqParam of(String uid, ChampionRaceRoundReportReq req) {
            RoundReportReqParam param = new RoundReportReqParam();
            param.setUid(uid);
            param.setReq(req);
            return param;
        }
    }

    @Data
    public static class UpdatePsParam {
        private ChampionRaceSpec spec;
        private ChampionRacePs eps;

        public static UpdatePsParam of(ChampionRaceSpec spec, ChampionRacePs eps) {
            UpdatePsParam param = new UpdatePsParam();
            param.setSpec(spec);
            param.setEps(eps);
            return param;
        }
    }

    @Data
    public static class QueryRedPacketParam {
        private ChampionRaceSpec spec;
        private String uid;

        public static QueryRedPacketParam of(ChampionRaceSpec spec, String uid) {
            QueryRedPacketParam param = new QueryRedPacketParam();
            param.setSpec(spec);
            param.setUid(uid);
            return param;
        }
    }

    @Data
    public static class QuerySpecPlaysParam{
        private ChampionRaceSpec spec;
        private int srvId;

        public static QuerySpecPlaysParam of(ChampionRaceSpec spec, int srvId) {
            QuerySpecPlaysParam param = new QuerySpecPlaysParam();
            param.setSpec(spec);
            param.setSrvId(srvId);
            return param;
        }
    }

    @Data
    public static class AdmireParam {
        private String uid;
        private int index;

        public static AdmireParam of(String uid, int index) {
            AdmireParam param = new AdmireParam();
            param.setUid(uid);
            param.setIndex(index);
            return param;
        }
    }

    @Data
    public static class QuerySpecTimerEventParam {
        private ChampionRaceSpec spec;

        public static QuerySpecTimerEventParam of (ChampionRaceSpec spec) {
            QuerySpecTimerEventParam param = new QuerySpecTimerEventParam();
            param.setSpec(spec);
            return param;
        }
    }
}
